using System;
using System.Collections.Generic;
using System.IO;
using ProtoBuf;
using Google.Protobuf;
using ProtoBuf.Message;
namespace ProtoBuf.Message{
   public class PBConvert{
       public static Object toObject(Int32 opCode, byte[] objectBytes) {
              return toObject(opCode, objectBytes, 0, objectBytes.Length);
       }
       public static Object toObject(Int32 opCode, byte[] objectBytes,int start,int count) {
            Object result = null;
            using (MemoryStream m = new MemoryStream(objectBytes,start,count)){
                switch (opCode) { 
#region 消息协议号 3001
                    case OpDefine.CSChatSend:
                        result =ProtoBuf.Message.CSChatSend.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCChatPush:
                        result =ProtoBuf.Message.SCChatPush.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSystemChatPush:
                        result =ProtoBuf.Message.SCSystemChatPush.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSChatOffLine:
                        result =ProtoBuf.Message.CSChatOffLine.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCChatOffLine:
                        result =ProtoBuf.Message.SCChatOffLine.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 1200
                    case OpDefine.CSTestEnterFight:
                        result =ProtoBuf.Message.CSTestEnterFight.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCTestEnterFight:
                        result =ProtoBuf.Message.SCTestEnterFight.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFightEnter:
                        result =ProtoBuf.Message.SCFightEnter.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSFightLoadState:
                        result =ProtoBuf.Message.CSFightLoadState.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFightLoadState:
                        result =ProtoBuf.Message.SCFightLoadState.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSFightBegin:
                        result =ProtoBuf.Message.CSFightBegin.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFightBegin:
                        result =ProtoBuf.Message.SCFightBegin.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSNextActionReady:
                        result =ProtoBuf.Message.CSNextActionReady.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCNextActionReady:
                        result =ProtoBuf.Message.SCNextActionReady.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFightRoundInfoSync:
                        result =ProtoBuf.Message.SCFightRoundInfoSync.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFightActionCampChange:
                        result =ProtoBuf.Message.SCFightActionCampChange.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSFightUnitAction:
                        result =ProtoBuf.Message.CSFightUnitAction.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFightUnitAction:
                        result =ProtoBuf.Message.SCFightUnitAction.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSFightQuit:
                        result =ProtoBuf.Message.CSFightQuit.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFightResult:
                        result =ProtoBuf.Message.SCFightResult.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 1051
                    case OpDefine.CSPlayerLogin:
                        result =ProtoBuf.Message.CSPlayerLogin.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCPlayerLogin:
                        result =ProtoBuf.Message.SCPlayerLogin.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCServerFull:
                        result =ProtoBuf.Message.SCServerFull.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSGetRandomName:
                        result =ProtoBuf.Message.CSGetRandomName.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCGetRandomName:
                        result =ProtoBuf.Message.SCGetRandomName.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSPlayerRename:
                        result =ProtoBuf.Message.CSPlayerRename.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCPlayerRename:
                        result =ProtoBuf.Message.SCPlayerRename.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSHeartBeat:
                        result =ProtoBuf.Message.CSHeartBeat.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCHeartBeat:
                        result =ProtoBuf.Message.SCHeartBeat.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSPlayerDisConnect:
                        result =ProtoBuf.Message.CSPlayerDisConnect.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 1300
                    case OpDefine.SCUpdateBag:
                        result =ProtoBuf.Message.SCUpdateBag.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCUpdateHeroBag:
                        result =ProtoBuf.Message.SCUpdateHeroBag.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSBagToHeroBag:
                        result =ProtoBuf.Message.CSBagToHeroBag.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSHeroBagExChange:
                        result =ProtoBuf.Message.CSHeroBagExChange.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 1000
                    case OpDefine.CSCheckDevicePreferPreset:
                        result =ProtoBuf.Message.CSCheckDevicePreferPreset.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCCheckDevicePreferPreset:
                        result =ProtoBuf.Message.SCCheckDevicePreferPreset.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSCheckVersion:
                        result =ProtoBuf.Message.CSCheckVersion.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCCheckVersion:
                        result =ProtoBuf.Message.SCCheckVersion.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSCheckActivation:
                        result =ProtoBuf.Message.CSCheckActivation.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCCheckActivation:
                        result =ProtoBuf.Message.SCCheckActivation.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSActivateAccount:
                        result =ProtoBuf.Message.CSActivateAccount.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCActivateAccount:
                        result =ProtoBuf.Message.SCActivateAccount.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSGetServerInfo:
                        result =ProtoBuf.Message.CSGetServerInfo.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCGetServerInfo:
                        result =ProtoBuf.Message.SCGetServerInfo.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSLoginCheckByName:
                        result =ProtoBuf.Message.CSLoginCheckByName.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCLoginCheckByName:
                        result =ProtoBuf.Message.SCLoginCheckByName.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSMainServerPoint:
                        result =ProtoBuf.Message.CSMainServerPoint.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCMainServerPoint:
                        result =ProtoBuf.Message.SCMainServerPoint.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSCheckCanReportErrorLog:
                        result =ProtoBuf.Message.CSCheckCanReportErrorLog.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCCheckCanReportErrorLog:
                        result =ProtoBuf.Message.SCCheckCanReportErrorLog.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSReportErrorLog:
                        result =ProtoBuf.Message.CSReportErrorLog.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCReportErrorLog:
                        result =ProtoBuf.Message.SCReportErrorLog.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCTellClientReportErrorLog:
                        result =ProtoBuf.Message.SCTellClientReportErrorLog.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 1100
                    case OpDefine.SCPlayerInfo:
                        result =ProtoBuf.Message.SCPlayerInfo.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 2001
                    case OpDefine.CSSceneLoading:
                        result =ProtoBuf.Message.CSSceneLoading.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneLoading:
                        result =ProtoBuf.Message.SCSceneLoading.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSSceneEnter:
                        result =ProtoBuf.Message.CSSceneEnter.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneEnter:
                        result =ProtoBuf.Message.SCSceneEnter.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSSceneTransfer:
                        result =ProtoBuf.Message.CSSceneTransfer.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneTransfer:
                        result =ProtoBuf.Message.SCSceneTransfer.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSSceneMove:
                        result =ProtoBuf.Message.CSSceneMove.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneForceDrag:
                        result =ProtoBuf.Message.SCSceneForceDrag.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneUnitStateUpdate:
                        result =ProtoBuf.Message.SCSceneUnitStateUpdate.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSSceneChangeMoveMode:
                        result =ProtoBuf.Message.CSSceneChangeMoveMode.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneChangeMoveMode:
                        result =ProtoBuf.Message.SCSceneChangeMoveMode.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSDialogInteraction:
                        result =ProtoBuf.Message.CSDialogInteraction.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCDialogInteraction:
                        result =ProtoBuf.Message.SCDialogInteraction.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCRefreshSceneUnitAOI:
                        result =ProtoBuf.Message.SCRefreshSceneUnitAOI.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSRequestSceneUnitInfo:
                        result =ProtoBuf.Message.CSRequestSceneUnitInfo.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCRequestSceneUnitInfo:
                        result =ProtoBuf.Message.SCRequestSceneUnitInfo.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSSceneGather:
                        result =ProtoBuf.Message.CSSceneGather.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneGather:
                        result =ProtoBuf.Message.SCSceneGather.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCSceneShowProUpdate:
                        result =ProtoBuf.Message.SCSceneShowProUpdate.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 100
                    case OpDefine.ErrorMessage:
                        result =ProtoBuf.Message.ErrorMessage.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SystemMessage:
                        result =ProtoBuf.Message.SystemMessage.Parser.ParseFrom(m);
                        break;
                    case OpDefine.GMDoSomething:
                        result =ProtoBuf.Message.GMDoSomething.Parser.ParseFrom(m);
                        break;
#endregion
#region 任务模块 4001-4099
                    case OpDefine.CSGetTaskList:
                        result =ProtoBuf.Message.CSGetTaskList.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCGetTaskList:
                        result =ProtoBuf.Message.SCGetTaskList.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSFinishTaskTarget:
                        result =ProtoBuf.Message.CSFinishTaskTarget.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFinishTaskTarget:
                        result =ProtoBuf.Message.SCFinishTaskTarget.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSAcceptTask:
                        result =ProtoBuf.Message.CSAcceptTask.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCAcceptTask:
                        result =ProtoBuf.Message.SCAcceptTask.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSFinishTask:
                        result =ProtoBuf.Message.CSFinishTask.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCFinishTask:
                        result =ProtoBuf.Message.SCFinishTask.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSGiveUpTask:
                        result =ProtoBuf.Message.CSGiveUpTask.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCGiveUpTask:
                        result =ProtoBuf.Message.SCGiveUpTask.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSTaskChapterInfo:
                        result =ProtoBuf.Message.CSTaskChapterInfo.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCTaskChapterInfo:
                        result =ProtoBuf.Message.SCTaskChapterInfo.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCRefreshCanAcceptTasks:
                        result =ProtoBuf.Message.SCRefreshCanAcceptTasks.Parser.ParseFrom(m);
                        break;
                    case OpDefine.CSTaskEnterFight:
                        result =ProtoBuf.Message.CSTaskEnterFight.Parser.ParseFrom(m);
                        break;
                    case OpDefine.SCTaskEnterFight:
                        result =ProtoBuf.Message.SCTaskEnterFight.Parser.ParseFrom(m);
                        break;
#endregion
#region 消息协议号 300
                    case OpDefine.SCProtobuffTestData:
                        result =ProtoBuf.Message.SCProtobuffTestData.Parser.ParseFrom(m);
                        break;
#endregion
                    default:
                        break;
                }
            }
            return result;
        }
        public static byte[] toBytes(Int32 opCode,Object obj){
            byte[] result = null;
            using (MemoryStream m = new MemoryStream()){
                IMessage msgObj = obj as IMessage;
                msgObj.WriteTo(m);
                m.Position = 0;
                int length = (int)m.Length;
                result = new byte[length];
                m.Read(result, 0, length);
            }
            return result;
        }
   }
}
